<template>
  <template v-if="user">
    <van-cell title="昵称" is-link to="/user/edit" :value="user.username" @click="toEdit('username','昵称',user.username)"/>
    <van-cell title="账户" :value="user.userAccount" />
    <van-cell title="头像" is-link to="/user/edit" >
      <img style="height: 48px" :src="user.avatarUrl">
    </van-cell>
    <van-cell title="当前用户" :value="user?.username" />
    <van-cell title="修改信息" is-link to="/user/update" />
    <van-cell title="我创建的队伍" is-link to="/team/create" />
    <van-cell title="我加入的队伍" is-link to="/team/join" />
    <van-cell title="退出登录" is-link to="/user/login" @click="logout"/>
  </template>
</template>

<script setup lang="ts">
import {useRouter} from "vue-router";
import {onMounted, ref} from "vue";
import {getCurrentUser} from "../services/user";
import moment from "moment/moment";
import myAxios from "../plugins/myAxios";
import {showFailToast, showSuccessToast} from "vant/es";

const user = ref();

onMounted(async ()=>{
  user.value=await getCurrentUser();
})

const router = useRouter();

const logout = async () => {
  const res = await myAxios.post("/user/logout");
  if (res?.code === 0 && res.data) {
    showSuccessToast('退出成功');
  } else {
    showFailToast('退出失败');
  }
}

const toEdit = (editKey: string, editName: string, currentValue: string) => {
  router.push({
    path: '/user/edit',
    query: {
      editKey,
      editName,
      currentValue,
    }
  })
}
</script>

<style scoped>

</style>